package com.lcredu.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 黎长容
 * @date 2025-07-18 23:44
 */
@Controller
@RequestMapping("/book")
public class BookHandler {

    @GetMapping("/getBook/{id}")
    public String getBook(@PathVariable("id") String id) {
        System.out.println("查询书籍 id=" + id);
        return "success";
    }

    @PostMapping("/addBook")
    public String addBook(String bookName) {
        System.out.println("成功添加书籍bookName= " + bookName);
        return "success";
    }

    //删除[DELETE]
    @DeleteMapping("/delBook/{id}")
    public String delBook(@PathVariable("id") String id) {
        System.out.println("删除书籍 id= " + id);
//        return "success";
//        这里解析成了:  /springmvc/book/success
        return "redirect:/book/success";
    }

    //修改[PUT]
    @PutMapping("/updateBook/{id}")
    public String updateBook(@PathVariable("id") String id) {
        System.out.println("修改书籍 id=" + id);
        //重定向到一个没有指定 method 的 Handler 方法
        return "redirect:/book/success";
    }


    //http://localhost:8080/springmvc/book/success
    //写一个转发到success页面的方法
    @RequestMapping("/success")
    public String success() {
        return "success";
    }


}
